module AutoBase
	class DefActionWord
    attr_accessor :param

    def initialize(session)
      @session = session
    end
    
    def def_action_word(&block)
      instance_eval(&block)
    end
    
    def call
      @action_word ||= AutoBase::ActionWord.new(@session)
    end

    def desc(value)
      @desc = value
      #AutoBase.debug "desc: #{value}"
    end

    def view(value)
      #AutoBase.debug "desc: #{value}"
      @view = value
    end

    def match(value = nil, &block)
      #AutoBase.debug "desc: #{value}"
      @match ||= []
      match = AutoBase::Match.new
      match.instance_eval(&block)
      @match << match
    end

    def command(value)
      @command = value
      #AutoBase.debug "desc: #{value}"


      cmd_creator = AutoBase::CommandLine.new
      cmd_creator.spec value
      cmd_creator.args param
      @command = cmd_creator.cmd
    end

    def version(value)
      #AutoBase.debug "desc: #{value}"
      @version = value
    end

    def deleted(&block)
      @deleted = AutoBase::DefActionWord.new(@session)
      @deleted.param = @param
      @deleted.instance_eval(&block)
      @deleted
    end
  end
end

module Kernel
	def def_action_word(&block)
    file = caller[0].split(':')[0..1].join(':')
    name = AutoBase::ActionWord::Index.name
    AutoBase::ActionWord::Index[name] = file
  end
end